package com.jxw.launcher.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.jxw.gk.SPUtils;
import com.jxw.launcher.MyApp;
import com.jxw.launcher.R;
import java.util.regex.Pattern;

/* loaded from: classes.dex */
public class DialogJmRegister extends Dialog {
    public static char[] chars = {'a', 'b', 'c', 'd', 'e', 'f', 'h', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};
    private OnConfirmClickListener onConfirmClickListener;
    Button register_go;
    EditText register_phone;
    EditText register_series;
    ImageView registered;

    /* loaded from: classes.dex */
    public interface OnConfirmClickListener {
        void onClick();
    }

    public void setOnConfirmClickListener(OnConfirmClickListener onConfirmClickListener) {
        this.onConfirmClickListener = onConfirmClickListener;
    }

    public DialogJmRegister(Context context) {
        super(context, R.style.Theme_Transparent);
    }

    @Override // android.app.Dialog
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.dialog_jmregister);
        Display defaultDisplay = getWindow().getWindowManager().getDefaultDisplay();
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        defaultDisplay.getSize(new Point());
        double width = defaultDisplay.getWidth();
        Double.isNaN(width);
        attributes.width = (int) (width * 0.7d);
        double height = defaultDisplay.getHeight();
        Double.isNaN(height);
        attributes.height = (int) (height * 0.7d);
        getWindow().setAttributes(attributes);
        setCanceledOnTouchOutside(true);
        setCancelable(true);
        getWindow().setDimAmount(0.7f);
        initView();
    }

    private void initView() {
        this.register_phone = (EditText) findViewById(R.id.register_phone);
        this.register_series = (EditText) findViewById(R.id.register_series);
        this.register_go = (Button) findViewById(R.id.register_go);
        this.registered = (ImageView) findViewById(R.id.registered);
        this.register_go.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.DialogJmRegister.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                boolean z;
                String obj = DialogJmRegister.this.register_phone.getText().toString();
                String obj2 = DialogJmRegister.this.register_series.getText().toString();
                if (obj != null && obj.length() == 0) {
                    Toast.makeText(DialogJmRegister.this.getContext(), "请输入手机号码", 0).show();
                } else if (obj != null && obj.length() != 11 && !DialogJmRegister.this.ispsd(obj)) {
                    Toast.makeText(DialogJmRegister.this.getContext(), "请输入正确的手机号码", 0).show();
                } else if (obj2 != null && obj2.length() == 0) {
                    Toast.makeText(DialogJmRegister.this.getContext(), "请输入注册号", 0).show();
                } else {
                    try {
                        Long.parseLong(obj2);
                        z = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                        z = false;
                    }
                    try {
                        if (!z) {
                            char c = 0;
                            for (int i = 0; i < obj2.length() - 1; i++) {
                                c = (char) (c ^ obj2.charAt(i));
                            }
                            if (obj2.charAt(obj2.length() - 1) == DialogJmRegister.chars[c % DialogJmRegister.chars.length]) {
                                MyApp.getInstance().getDeviceSerial();
                            }
                        } else if (obj2.length() == 10) {
                            int charAt = obj2.charAt(8) - '0';
                            int charAt2 = obj2.charAt(1) - '0';
                            int charAt3 = obj2.charAt(2) - '0';
                            int charAt4 = obj2.charAt(3) - '0';
                            if ((obj2.charAt(0) - '0') * 2 == charAt && Math.abs(charAt2 - charAt3) == charAt4) {
                                String deviceSerial = MyApp.getInstance().getDeviceSerial();
                                if ("unknown".equals(deviceSerial) || TextUtils.isEmpty(deviceSerial)) {
                                    deviceSerial = MyApp.getInstance().getDeviceSerialx();
                                }
                                if ("unknown".equals(deviceSerial) || TextUtils.isEmpty(deviceSerial)) {
                                    deviceSerial = MyApp.getInstance().get_JzyhSN();
                                }
                                Log.e("DialogJmRegister", "假码注册获取sn号=" + deviceSerial);
                                DialogJmRegister.this.registered.setVisibility(0);
                                SPUtils.saveString("jmRegister", "1");
                            }
                        } else {
                            Toast.makeText(DialogJmRegister.this.getContext(), "请输入正确的注册号", 0).show();
                        }
                    } catch (Exception unused) {
                    }
                    DialogJmRegister.this.registered.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.DialogJmRegister.1.1
                        @Override // android.view.View.OnClickListener
                        public void onClick(View view2) {
                            DialogJmRegister.this.dismiss();
                        }
                    });
                }
            }
        });
    }

    public boolean ispsd(String str) {
        return Pattern.compile("^[0-9]*$").matcher(str).matches();
    }
}
